package p270jp.pxv.android.activity;

import android.content.ComponentCallbacks;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.activity.ComponentActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelStore;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import p014ae.AbstractActivityC0130o2;
import p014ae.View$OnClickListenerC0046a;
import p014ae.View$OnClickListenerC0050b;
import p014ae.View$OnClickListenerC0054c;
import p014ae.View$OnClickListenerC0163u;
import p045be.PointPagerAdapter;
import p047bg.C1124a;
import p056bp.ZonedDateTime;
import p060c2.Chain;
import p064c6.Preconditions;
import p081cn.progressionUtil;
import p189gn.AbstractC3435a;
import p189gn.AbstractC3446l;
import p210hh.PixivAccountManager;
import p216hn.Lambda;
import p216hn.Reflection;
import p270jp.pxv.android.R;
import p270jp.pxv.android.model.point.PPointMostRecentExpiration;
import p270jp.pxv.android.model.point.PPointSummary;
import p270jp.pxv.android.model.point.PerServiceBalance;
import p270jp.pxv.android.response.PixivResponse;
import p294ko.ViewModelOwner;
import p314lg.ActivityPointBinding;
import p325m0.MutabilityOwnership;
import p350mp.Timber;
import p370ni.InfoType;
import p467rd.subscribers;
import p484s6.C5998s;
import p547uh.PixivPointDetailsBottomSheetFragment;
import p579vo.Qualifier;
import p603wm.AbstractC6949c;
import p603wm.Unit;
import p629xm.IteratorsJVM;
import p629xm._Collections;
import p645yc.AndroidSchedulers;
import p653yk.PixivPointStore;
import p671zc.CompositeDisposable;
import p671zc.Disposable;

/* compiled from: PointActivity.kt */
/* renamed from: jp.pxv.android.activity.PointActivity */
/* loaded from: classes2.dex */
public final class PointActivity extends AbstractActivityC0130o2 {

    /* renamed from: N */
    public static final /* synthetic */ int f18516N;

    /* renamed from: I */
    public final AbstractC6949c f18517I = Preconditions.m9802P(1, new C4061d(this, null, null));

    /* renamed from: J */
    public final ArrayList<PixivPointDetailsBottomSheetFragment.C6592a> f18518J = new ArrayList<>();

    /* renamed from: K */
    public final AbstractC6949c f18519K = Preconditions.m9802P(3, new C4063f(this, null, null, new C4062e(this), null));

    /* renamed from: L */
    public long f18520L;

    /* renamed from: M */
    public ActivityPointBinding f18521M;

    /* compiled from: PointActivity.kt */
    /* renamed from: jp.pxv.android.activity.PointActivity$a */
    /* loaded from: classes2.dex */
    public static final class C4058a extends Lambda implements AbstractC3446l<Throwable, Unit> {
        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4058a() {
            super(1);
            PointActivity.this = r1;
        }

        @Override // p189gn.AbstractC3446l
        public Unit invoke(Throwable th) {
            Throwable th2 = th;
            MutabilityOwnership.m3745m(th2, "it");
            PointActivity pointActivity = PointActivity.this;
            ActivityPointBinding y0Var = pointActivity.f18521M;
            if (y0Var != null) {
                y0Var.f22478t.m4595d(InfoType.UNKNOWN_ERROR, new View$OnClickListenerC0054c(pointActivity, 4));
                Timber.f23100a.mo3526c(th2, "request error", new Object[0]);
                return Unit.f29503a;
            }
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
    }

    /* compiled from: PointActivity.kt */
    /* renamed from: jp.pxv.android.activity.PointActivity$b */
    /* loaded from: classes2.dex */
    public static final class C4059b extends Lambda implements AbstractC3446l<PixivResponse, Unit> {
        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4059b() {
            super(1);
            PointActivity.this = r1;
        }

        @Override // p189gn.AbstractC3446l
        public Unit invoke(PixivResponse pixivResponse) {
            PixivResponse pixivResponse2 = pixivResponse;
            ActivityPointBinding y0Var = PointActivity.this.f18521M;
            if (y0Var != null) {
                if (y0Var.f22483y.getAdapter() == null) {
                    PointActivity pointActivity = PointActivity.this;
                    ActivityPointBinding y0Var2 = pointActivity.f18521M;
                    if (y0Var2 != null) {
                        ViewPager viewPager = y0Var2.f22483y;
                        FragmentManager K0 = pointActivity.m11131K0();
                        MutabilityOwnership.m3746l(K0, "supportFragmentManager");
                        String string = pointActivity.getString(R.string.point_tab_title_gain);
                        MutabilityOwnership.m3746l(string, "getString(jp.pxv.android…ing.point_tab_title_gain)");
                        String string2 = pointActivity.getString(R.string.point_tab_title_loss);
                        MutabilityOwnership.m3746l(string2, "getString(jp.pxv.android…ing.point_tab_title_loss)");
                        viewPager.setAdapter(new PointPagerAdapter(K0, Chain.m9925y(string, string2)));
                    } else {
                        MutabilityOwnership.m3737u("binding");
                        throw null;
                    }
                }
                ActivityPointBinding y0Var3 = PointActivity.this.f18521M;
                if (y0Var3 != null) {
                    y0Var3.f22478t.m4598a();
                    PointActivity pointActivity2 = PointActivity.this;
                    PPointSummary pPointSummary = pixivResponse2.summary;
                    MutabilityOwnership.m3746l(pPointSummary, "it.summary");
                    Objects.requireNonNull(pointActivity2);
                    List<PerServiceBalance> perServiceBalances = pPointSummary.getPerServiceBalances();
                    ArrayList arrayList = new ArrayList();
                    for (Object obj : perServiceBalances) {
                        if (!((PerServiceBalance) obj).isUsageLimited()) {
                            arrayList.add(obj);
                        }
                    }
                    ArrayList arrayList2 = new ArrayList(IteratorsJVM.m703K(arrayList, 10));
                    Iterator it = arrayList.iterator();
                    while (it.hasNext()) {
                        arrayList2.add(Long.valueOf(((PerServiceBalance) it.next()).getBalance()));
                    }
                    long e0 = _Collections.m683e0(arrayList2);
                    List<PerServiceBalance> perServiceBalances2 = pPointSummary.getPerServiceBalances();
                    ArrayList arrayList3 = new ArrayList();
                    for (Object obj2 : perServiceBalances2) {
                        if (((PerServiceBalance) obj2).isUsageLimited()) {
                            arrayList3.add(obj2);
                        }
                    }
                    ArrayList arrayList4 = new ArrayList(IteratorsJVM.m703K(arrayList3, 10));
                    Iterator it2 = arrayList3.iterator();
                    while (it2.hasNext()) {
                        arrayList4.add(Long.valueOf(((PerServiceBalance) it2.next()).getBalance()));
                    }
                    long e02 = _Collections.m683e0(arrayList4);
                    long j = e0 + e02;
                    pointActivity2.f18520L = j;
                    ActivityPointBinding y0Var4 = pointActivity2.f18521M;
                    if (y0Var4 != null) {
                        y0Var4.f22475q.setText(Preconditions.m9814D(j));
                        if (e02 > 0) {
                            ActivityPointBinding y0Var5 = pointActivity2.f18521M;
                            if (y0Var5 != null) {
                                y0Var5.f22481w.setText(Preconditions.m9814D(e02));
                            } else {
                                MutabilityOwnership.m3737u("binding");
                                throw null;
                            }
                        } else {
                            ActivityPointBinding y0Var6 = pointActivity2.f18521M;
                            if (y0Var6 != null) {
                                y0Var6.f22482x.setVisibility(8);
                            } else {
                                MutabilityOwnership.m3737u("binding");
                                throw null;
                            }
                        }
                        if (!pPointSummary.getExpirations().isEmpty()) {
                            PPointMostRecentExpiration pPointMostRecentExpiration = pPointSummary.getExpirations().get(0);
                            String D = Preconditions.m9814D(pPointMostRecentExpiration.getBalance());
                            ZonedDateTime expiredDatetime = pPointMostRecentExpiration.getExpiredDatetime();
                            String string3 = pointActivity2.getString(R.string.point_expiration_date_format, new Object[]{Integer.valueOf(expiredDatetime.f5134b.f5078b.f5074c), Integer.valueOf(expiredDatetime.f5134b.f5078b.f5075d)});
                            MutabilityOwnership.m3746l(string3, "getString(jp.pxv.android…lue, dateTime.dayOfMonth)");
                            String string4 = pointActivity2.getString(R.string.point_suffix, new Object[]{D});
                            MutabilityOwnership.m3746l(string4, "getString(jp.pxv.android…suffix, formattedBalance)");
                            String string5 = pointActivity2.getString(R.string.point_expiration_message, new Object[]{string3, string4});
                            MutabilityOwnership.m3746l(string5, "getString(jp.pxv.android… dateString, pointString)");
                            ActivityPointBinding y0Var7 = pointActivity2.f18521M;
                            if (y0Var7 != null) {
                                y0Var7.f22477s.setText(string5);
                            } else {
                                MutabilityOwnership.m3737u("binding");
                                throw null;
                            }
                        } else {
                            ActivityPointBinding y0Var8 = pointActivity2.f18521M;
                            if (y0Var8 != null) {
                                y0Var8.f22477s.setVisibility(8);
                            } else {
                                MutabilityOwnership.m3737u("binding");
                                throw null;
                            }
                        }
                        pointActivity2.f18518J.clear();
                        Iterator it3 = arrayList3.iterator();
                        while (it3.hasNext()) {
                            PerServiceBalance perServiceBalance = (PerServiceBalance) it3.next();
                            String displayName = perServiceBalance.getService().getDisplayName();
                            String D2 = Preconditions.m9814D(perServiceBalance.getBalance());
                            MutabilityOwnership.m3746l(D2, "formatPointText(it.balance)");
                            pointActivity2.f18518J.add(new PixivPointDetailsBottomSheetFragment.C6592a(displayName, D2));
                        }
                        return Unit.f29503a;
                    }
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
    }

    /* compiled from: PointActivity.kt */
    /* renamed from: jp.pxv.android.activity.PointActivity$c */
    /* loaded from: classes2.dex */
    public static final class C4060c extends Lambda implements AbstractC3446l<Unit, Unit> {
        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4060c() {
            super(1);
            PointActivity.this = r1;
        }

        @Override // p189gn.AbstractC3446l
        public Unit invoke(Unit jVar) {
            PointActivity.m4772V0(PointActivity.this);
            return Unit.f29503a;
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.activity.PointActivity$d */
    /* loaded from: classes2.dex */
    public static final class C4061d extends Lambda implements AbstractC3435a<CompositeDisposable> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f18525a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4061d(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f18525a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [zc.a, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final CompositeDisposable invoke() {
            return C1124a.m10173s(this.f18525a).f24118a.m920a().m621a(Reflection.m5499a(CompositeDisposable.class), null, null);
        }
    }

    /* compiled from: ActivityExt.kt */
    /* renamed from: jp.pxv.android.activity.PointActivity$e */
    /* loaded from: classes2.dex */
    public static final class C4062e extends Lambda implements AbstractC3435a<ViewModelOwner> {

        /* renamed from: a */
        public final /* synthetic */ ComponentActivity f18526a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4062e(ComponentActivity componentActivity) {
            super(0);
            this.f18526a = componentActivity;
        }

        @Override // p189gn.AbstractC3435a
        public ViewModelOwner invoke() {
            ComponentActivity componentActivity = this.f18526a;
            MutabilityOwnership.m3745m(componentActivity, "storeOwner");
            ViewModelStore viewModelStore = componentActivity.getViewModelStore();
            MutabilityOwnership.m3746l(viewModelStore, "storeOwner.viewModelStore");
            return new ViewModelOwner(viewModelStore, componentActivity);
        }
    }

    /* compiled from: ActivityExt.kt */
    /* renamed from: jp.pxv.android.activity.PointActivity$f */
    /* loaded from: classes2.dex */
    public static final class C4063f extends Lambda implements AbstractC3435a<PixivPointStore> {

        /* renamed from: a */
        public final /* synthetic */ ComponentActivity f18527a;

        /* renamed from: b */
        public final /* synthetic */ AbstractC3435a f18528b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4063f(ComponentActivity componentActivity, Qualifier aVar, AbstractC3435a aVar2, AbstractC3435a aVar3, AbstractC3435a aVar4) {
            super(0);
            this.f18527a = componentActivity;
            this.f18528b = aVar3;
        }

        /* JADX WARN: Type inference failed for: r0v1, types: [androidx.lifecycle.j0, yk.c] */
        @Override // p189gn.AbstractC3435a
        public PixivPointStore invoke() {
            return progressionUtil.m9685e(this.f18527a, null, null, this.f18528b, Reflection.m5499a(PixivPointStore.class), null);
        }
    }

    /* renamed from: V0 */
    public static final void m4772V0(PointActivity pointActivity) {
        ActivityPointBinding y0Var = pointActivity.f18521M;
        if (y0Var != null) {
            y0Var.f22478t.m4595d(InfoType.LOADING, null);
            pointActivity.m4770X0();
            return;
        }
        MutabilityOwnership.m3737u("binding");
        throw null;
    }

    /* renamed from: W0 */
    public final CompositeDisposable m4771W0() {
        return (CompositeDisposable) this.f18517I.getValue();
    }

    /* renamed from: X0 */
    public final void m4770X0() {
        Disposable e = subscribers.m2591e(PixivAccountManager.m5511e().m5513c().m970f(C5998s.f26039x).m966j(AndroidSchedulers.m334a()), new C4058a(), new C4059b());
        CompositeDisposable W0 = m4771W0();
        MutabilityOwnership.m3744n(W0, "compositeDisposable");
        W0.mo82c(e);
    }

    @Override // p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        ViewDataBinding d = DataBindingUtil.m11369d(this, R.layout.activity_point);
        MutabilityOwnership.m3746l(d, "setContentView(this, R.layout.activity_point)");
        ActivityPointBinding y0Var = (ActivityPointBinding) d;
        this.f18521M = y0Var;
        C1124a.m10197Q(this, y0Var.f22480v, R.string.point_name);
        ActivityPointBinding y0Var2 = this.f18521M;
        if (y0Var2 != null) {
            y0Var2.f22478t.m4595d(InfoType.LOADING, null);
            ActivityPointBinding y0Var3 = this.f18521M;
            if (y0Var3 != null) {
                TabLayout tabLayout = y0Var3.f22479u;
                if (y0Var3 != null) {
                    tabLayout.setupWithViewPager(y0Var3.f22483y);
                    ActivityPointBinding y0Var4 = this.f18521M;
                    if (y0Var4 != null) {
                        y0Var4.f22476r.setOnClickListener(new View$OnClickListenerC0163u(this, 4));
                        ActivityPointBinding y0Var5 = this.f18521M;
                        if (y0Var5 != null) {
                            y0Var5.f22477s.setOnClickListener(new View$OnClickListenerC0050b(this, 6));
                            ActivityPointBinding y0Var6 = this.f18521M;
                            if (y0Var6 != null) {
                                y0Var6.f22482x.setOnClickListener(new View$OnClickListenerC0046a(this, 4));
                                Disposable g = subscribers.m2589g(((PixivPointStore) this.f18519K.getValue()).f30915e.m986o(AndroidSchedulers.m334a()), null, null, new C4060c(), 3);
                                CompositeDisposable W0 = m4771W0();
                                MutabilityOwnership.m3744n(W0, "compositeDisposable");
                                W0.mo82c(g);
                                m4770X0();
                                return;
                            }
                            MutabilityOwnership.m3737u("binding");
                            throw null;
                        }
                        MutabilityOwnership.m3737u("binding");
                        throw null;
                    }
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
        MutabilityOwnership.m3737u("binding");
        throw null;
    }

    @Override // p270jp.pxv.android.activity.BaseActivity, p116e.ActivityC2727f, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        m4771W0().m80f();
        super.onDestroy();
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        MutabilityOwnership.m3745m(menuItem, "item");
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        this.f940i.m12030b();
        return true;
    }
}
